//
//  TLPublishViewController.m
//  Home
//
//  Created by 陶亮 on 16/7/1.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "TLPublishViewController.h"

@interface TLPublishViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *publicTableview;
    NSArray *titleArray;
    NSMutableArray *sectionArray;
    UIView *cellView;
    UIView *footerView;
    UIButton *button;
    NSInteger number ;
    NSMutableArray *rowArray;
    NSMutableDictionary *dic;
    NSIndexPath *indexpath;
    NSMutableArray *dicArray;
}
@end

@implementation TLPublishViewController

- (void)viewDidLoad {
    number = 1;
    dicArray = [NSMutableArray arrayWithObject:@{@[]:@0}];
    [super viewDidLoad];
    rowArray = [NSMutableArray arrayWithObject:@"image"];
    publicTableview = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStyleGrouped];
    publicTableview.delegate = self;
    publicTableview.dataSource = self;
    [self.view addSubview:publicTableview];
    sectionArray = [NSMutableArray new];
    footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 100)];
    footerView.backgroundColor = [UIColor magentaColor];
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    [footerView addSubview:button];
    button.backgroundColor = [UIColor whiteColor];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(footerView.mas_centerX);
        make.top.equalTo(footerView).offset(10);
        make.size.mas_equalTo(CGSizeMake(KScreenWidth-100, 40));
        
        
    }];
    [button addTarget:self action:@selector(foot:) forControlEvents:UIControlEventTouchUpInside];
    publicTableview.tableFooterView = footerView;
    
    // Do any additional setup after loading the view.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//    NSLog(@"22222=%ld",number);
////    if (indexPath.section == 0) {
////        return 1;
////    }
////    
////    else {
//    NSInteger count = number;
//    
//        return count;
//    }
    
    
    return dicArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    NSLog(@"3333==%ld",rowArray.count);
//    NSLog(@"4444==%ld",number);
//    section = indexpath.section;
//    NSLog(@"555%@",dic);
//    NSLog(@"6666==%@",[dic objectForKey:[NSString stringWithFormat:@"%ld",number-1]]) ;
//    NSMutableArray *array = [dic objectForKey:[NSString stringWithFormat:@"%ld",number-1]];
//   
//    return array.count;
//    
      NSLog(@"nnnn=%@",dicArray);
   
    if (section == 0) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[0] objectForKey:@"0" ]];
        NSLog(@"==========%ld",aaa.count);
        return aaa.count;
    }
    if (section ==1) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[1] objectForKey:@"1" ]];
        NSLog(@"==========%ld",aaa.count);

        return aaa.count;
    }
    if (section ==2) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[2] objectForKey:@"2" ]];
        NSLog(@"==========%ld",aaa.count);

        return aaa.count;
    }
    if (section ==3) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[3] objectForKey:@"3" ]];
        NSLog(@"==========%ld",aaa.count);
        return aaa.count;
    } if (section ==4) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[4] objectForKey:@"4" ]];
        return aaa.count;
    } if (section ==5) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[5] objectForKey:@"5" ]];
        NSLog(@"==========%ld",aaa.count);

        return aaa.count;
    } if (section ==6) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[6] objectForKey:@"6" ]];
        NSLog(@"==========%ld",aaa.count);

        return aaa.count;
    } if (section ==7) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[7] objectForKey:@"7" ]];
        return aaa.count;
    } if (section ==8) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[8] objectForKey:@"8" ]];
        return aaa.count;
    } if (section ==9) {
        NSMutableArray *aaa= [NSMutableArray arrayWithArray:[dicArray[9] objectForKey:@"9" ]];
        return aaa.count;
    }
    
    
    else return 1;
  
//    NSInteger result = 0;
//     NSMutableArray *array1 = [dicArray[number-1] objectForKey:[NSString stringWithFormat:@"%ld",(long)number-1]];
//    NSMutableArray *numberArray = [NSMutableArray arrayWithObject:@1];
//    [numberArray insertObject:[NSString stringWithFormat:@"%ld",array1.count] atIndex:numberArray.count];
//    NSLog(@"-----%@",array1);
//    NSLog(@"----1%@",array1[section]);
//    if ((section = 0)) {
//        return array1.count;
//    }
//    return (NSInteger)numberArray.count;
//    if ([tableView isEqual:publicTableview]) {
//
//        NSMutableArray *array2 = [dicArray[dicArray.count - 1] objectForKey:[NSString stringWithFormat:@"%ld",(long)2]];
//    NSLog(@"mmm1=%ld",array2.count);
//        NSMutableArray *array3 = [dicArray[dicArray.count - 2] objectForKey:[NSString stringWithFormat:@"%ld",(long)3]];
//    NSLog(@"mmm2=%ld",array3.count);
//        NSMutableArray *array4 = [dicArray[dicArray.count - 3] objectForKey:[NSString stringWithFormat:@"%ld",(long)4]];
//    NSLog(@"mmm3=%ld",array3.count);


//        switch (section) {
//            case 0:
//                result = array1.count;
//                break;
//                case 1:
//                
//                result = array2.count;
//                break;
//                case 2:
//                result = array3.count;
//                break;
//            case 3:
//                result = array4.count;
//                break;
//            case 4:
//                result = array4.count;
//                break;
//          
//        }
        
        
        
        
        
        
//        }//
//   
//    return ;
//   
    
//    return [dic objectForKey:[NSString stringWithFormat:@"%ld",(long)number]].count;
    
  
    
    

}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.section == 0) {
        return  100;
//    }
//    else{
//    
//    
//        return 100 *rowArray.count;
//    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"%ld,%ld",(long)indexPath.section,(long)indexPath.row]];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"%ld,%ld",(long)indexPath.section,(long)indexPath.row]];
   
        cellView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 100)];
        cellView.backgroundColor = [UIColor redColor];
        [cell addSubview:cellView];
    
    
    }
    
    
    return cell;

}
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//
//    return 120;
//}
//-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//
//   
//    return footerView;
//    
//
//}
-(void)foot:(UIButton *)foo{
    NSLog(@"00000=%ld",number);

    NSLog(@"11111=%ld",number);
    [rowArray insertObject:@"cell" atIndex:0];
    dic = [NSMutableDictionary dictionaryWithObject:rowArray forKey:[NSString stringWithFormat:@"%ld",number]];
    [dicArray insertObject:dic atIndex:dicArray.count];
    NSLog(@"dic==%@",dic);
    NSLog(@"arrr==%@",dicArray);
     number ++;
    [publicTableview reloadData];


}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
